package Entity;
import java.util.Date;
import Controller.DBcontroller;
import Entity.Prices.pvalidateErrs;

/**
 * This class is for request for changing rates. 
 * Every parking lot manager can request for changing his rates.
 * 
 * @author Moran Abilea
 *
 */
public class Request {
	
	private boolean askedForChange; // this is a flag that indicates if the parking lot manager wants to change the rates.
	private boolean approvedOrdenied; // this is a flag that indicates if the company manager approve or deny the request.
	private Date dateOfApproval; // this is the date of approval, which is relevant only for the company manager.
	private Prices changePrices; // this is the prices that the parking lot manager want to change.
	private int parkingLotNumber; // this is the parking lot number of the request. must be between 1 to 6.
	
	/**
	 * is the constructor for creating a new request.
	 * This constructor will create a default prices (5 sh for occational price and 4 sh for ordered price and also calculate the other prices as well).
	 * @param parknum =  in order to know which parking lot prices we will need to handle.
	 */
	// this is the constructor of creating a request for changing rates (will be used for saving).
	public Request(int parknum){
			changePrices=new Prices(parknum); // creating the default prices until the parking lot manager will change it.
			this.askedForChange=true; // set the flag to true.
			this.approvedOrdenied=false; // set the flag to false.
		}
	
	/**
	 * is the active constructor for creating a new request with known new prices.
	 * @param parknum =  in order to know which parking lot prices we will need to handle.
	 * @param firstchange =the first price (also known as the new occational parking place price).
	 * @param secondchange = the second price (also known as the new ordered parking place price).
	 */
	// this is the constructor of creating a request for changing rates.
	public Request(int parknum,double firstchange,double secondchange){
		changePrices=new Prices(parknum); // creating the default prices until the parking lot manager will change it.
		//copy the new prices as it. 
		changePrices.setOccasionalParkingPlace(firstchange); 
		changePrices.setOrderedParkingPlace(secondchange);
		this.askedForChange=true; // set the flag to true.
		this.approvedOrdenied=false; // set the flag to false.
	}
	
	// the get functions
	public Prices getChangePrices() {return changePrices;}
	public Date getDateOfApproval() {return dateOfApproval;}
	public int getParkingLotNumber() {return parkingLotNumber;}
	public boolean isApprovedOrdenied() {return approvedOrdenied;}
	public boolean isAskedForChange() {return askedForChange;}
	
	// the set functions
	public void setApprovedOrdenied(boolean approvedOrdenied) {this.approvedOrdenied = approvedOrdenied;}
	public void setAskedForChange(boolean askedForChange) {this.askedForChange = askedForChange;}
	public void setChangePrices(Prices changePrices) {this.changePrices = changePrices;}
	public void setParkingLotNumber(int parkingLotNumber) {this.parkingLotNumber = parkingLotNumber;}
	public void setDateOfApproval(Date dateOfApproval) {this.dateOfApproval = dateOfApproval;}
	
	/**
	 * is the function for validate the input from the parking lot manager.
	 * @return which error occurs.(OCCERR for error in occational price or ORDERR for error in the ordered price).
	 */
	// this is a function for validation.
	public pvalidateErrs validate()
	{
		if(this.changePrices.validate()==pvalidateErrs.OCCERR)
			return pvalidateErrs.OCCERR;
		if(this.changePrices.validate()==pvalidateErrs.ORDERR)
			return pvalidateErrs.ORDERR;
		return null;
	}
	
	/**
	 * is the fucntion for saving the new request to DB.
	 */
	// this function is for saving complaint to the DB.
	public void save()
	{
		Request r=new Request(this.parkingLotNumber);
		DBcontroller.saveRequestToDB(r);
	}
}
